using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

namespace ClientGUI.Widgets
{
    class MessageStatusbar:StatusBar
    {
        Label status_lbl;
        public MessageStatusbar()
        {
            status_lbl = new Label();
            Controls.Add(status_lbl);
            Resize += new EventHandler(MessageStatusbar_Resize);
        }

        void MessageStatusbar_Resize(object sender, EventArgs e)
        {
            status_lbl.Width = Width - 2;
        }


        System.Threading.Timer my_status_timer = null;
        delegate void StatusAway(String msg);
        /// <summary>
        /// Sets the status bar and removes the message after a timeout
        /// </summary>
        /// <param name="message"></param>
        public void StatusMessage(String message)
        {
            if (my_status_timer != null)
            {
                my_status_timer.Dispose();
                my_status_timer = null;
            }
            System.Threading.TimerCallback callback = delegate(object state)
            {
                if (!IsDisposed) {
                    Invoke(new StatusAway(StatusMessage), "");

                    my_status_timer.Dispose();
                    my_status_timer = null;
                }
            };
            my_status_timer = new System.Threading.Timer(callback, null, 5000, 1000);

            status_lbl.Text = message;
        }
        public String Status { get { return status_lbl.Text; } }

        /// <summary>
        /// Delete a status bar
        /// </summary>
        public new void Dispose()
        {
            if (my_status_timer != null)
                my_status_timer.Dispose();
            base.Dispose();
        }
    }
}
